﻿@using BlogEngine.Core
@using BlogEngine.Core.Packaging

@helper CurrentClass(string pg)
{
    var current = "class=\"content-box-selected\"";
    if (Request.Path.ToLower().Contains(pg.ToLower()))
    {
        __razor_helper_writer.Write(current);
    }
}

@helper InstalledThemes()
{
    var path = Server.MapPath(string.Format("{0}themes/", Utils.ApplicationRelativeWebRoot));
    var loaderSrc = Path.Combine(Utils.ApplicationRelativeWebRoot, "pics/ajax-loader.gif");

    var currTheme = PackageRepository.GetPackage(BlogSettings.Instance.Theme);  
    var currMobileTheme = PackageRepository.GetPackage(BlogSettings.Instance.MobileTheme);
    
    <h2 class="gallery-hdr">@Resources.labels.activeThemes</h2>
    <div class="installed-themes">
        <ul class="gallery">
            <li class="pkg-installed">
                <div class="Theme">
                    <div class="pkg-hdr">
                        <div class="pkg-img">
                            <img src="@currTheme.IconUrl" class="thumbnail" alt="current theme" />
                        </div>
                        <div class="prop-hdr">
                            <h2>@Resources.labels.currentTheme: @BlogSettings.Instance.Theme</h2>
                            @if (!string.IsNullOrWhiteSpace(currTheme.Authors))
                            {
                            <p>@Resources.labels.author: @currTheme.Authors</p> 
                            }
                            @if (!string.IsNullOrWhiteSpace(currTheme.LocalVersion))
                            {
                            <p>Version: @currTheme.LocalVersion</p> 
                            }
                        </div>
                    </div>
                    
                </div>
            </li>
            <li class="pkg-installed">
                <div class="Theme">
                    <div class="pkg-hdr">
                        <div class="pkg-img">
                            <img src="@currMobileTheme.IconUrl" class="thumbnail" alt="mobile theme" />
                        </div>
                        <div class="prop-hdr">
                            <h2>@Resources.labels.mobileTheme: @BlogSettings.Instance.MobileTheme</h2>
                            @if (!string.IsNullOrWhiteSpace(currMobileTheme.Authors))
                            {
                            <p>@Resources.labels.author: @currMobileTheme.Authors</p> 
                            }
                            @if (!string.IsNullOrWhiteSpace(currMobileTheme.LocalVersion))
                            {
                            <p>Version: @currMobileTheme.LocalVersion</p> 
                            }
                        </div>
                    </div>
                    
                </div>
            </li>
        </ul>
    </div>
   
    <h2>@Resources.labels.available</h2>
    <div class="available-themes">
        <ul class="gallery">
        @foreach (var theme in PackageRepository.LocalPackages(Constants.Theme))
        {
        <li id="@theme.Id">
            <div class="Theme">
                <div class="pkg-hdr">
                    <div class="pkg-img">
                        <img src="@theme.IconUrl" class="thumbnail" alt="theme" />
                    </div>
                    <div class="prop-hdr">
                        <h2>@theme.Id</h2>
                        @if (!string.IsNullOrWhiteSpace(theme.Authors))
                        {
                        <p>@Resources.labels.author: @theme.Authors</p>   
                        }
                        else
                        {
                        <p>@Resources.labels.author: unknown</p>
                        }
                        @if (!string.IsNullOrWhiteSpace(theme.LocalVersion))
                        {
                        <p>Version: @theme.LocalVersion</p> 
                        }
                        @if (Blog.CurrentInstance.IsPrimary && @theme.Location == "I")
                        {
                            if (Gallery.ConvertVersion(theme.LocalVersion) < Gallery.ConvertVersion(theme.OnlineVersion)){
                            <p id="upd-@theme.Id" class="package-update local">
                                <a href="" onclick="UpdatePackage('@theme.Id','L'); return false;">@Resources.labels.update</a>
                            </p>    
                            }
                            <p id="del-@theme.Id" class="package-delete">
                                <a href="" id="a-@theme.Id" class="deleteAction" onclick="UninstallPackage('@theme.Id'); return false;">@Resources.labels.delete</a>
                            </p>
                        }
                    </div>
                </div>
                <div class="pkg-desc">
                    <p>
                        <a href="" onclick="SetCurrentTheme('@theme.Id','false'); return false;">@Resources.labels.setAsCurrentTheme</a>&nbsp;|
                        <a href="" onclick="SetCurrentTheme('@theme.Id','true'); return false;">@Resources.labels.setAsMobileTheme</a>&nbsp;|
                        <a href="" onclick="window.open('@Path.Combine(Blog.CurrentInstance.RelativeWebRoot, "?theme=")@theme.Id','themepreview','width=1000,height=700,scrollbars=yes,resizable=yes'); return false">@Resources.labels.preview</a>
                    </p>
                </div>
            </div>
        </li>
        }
        </ul>
    </div>
}
